#include <QDebug>
#include "inputmethod.h"

InputMethod::InputMethod()
{
    showflag=0;
    keyboard = new KeyBoard;
    if (DebugOrRelease)
        this->setCursor(Qt::CrossCursor);
    setWindowFlags(Qt::Tool|Qt::WindowStaysOnTopHint);
}

InputMethod::~InputMethod()
{
    delete keyboard;
}

/*
* Name : void eventFilter(QObject *obj, QEvent *event);
* Type : QEvent
* Func : judge input method event
* In   : QObject,QEvent
* Out  : bool
*/
bool InputMethod::eventFilter(QObject *obj, QEvent *event)
{
    if(event->type()==QEvent::MouseButtonPress)
    {
        emit setImObjName(obj->objectName()); //send the Object Name of event to judge who trigger it
        ////) <<obj->objectName();
        showKeyBoard();
        return true;
    }

    return QObject::eventFilter(obj,event);
}


/*
* Name : void showKeyBoard();
* Type : function
* Func : show keyBoard
* In   : Null
* Out  : Null
*/
void InputMethod::showKeyBoard()
{
    system("rm /tmp/checkkeyboard");
    system("cat /proc/bus/input/devices > /tmp/checkkeyboard");
    QFile filecmd("/tmp/checkkeyboard");
    filecmd.open(QIODevice::ReadWrite);
    QString nametmp(filecmd.readAll());
    QString havekeyboard="Keyboard";
    QString havekeyboard1="keyboard";
    if( nametmp.contains(havekeyboard) || nametmp.contains(havekeyboard1) )
        showflag=1;
    else
        showflag=0;

if(!showflag){
    keyboard->setWindowFlags(Qt::Tool|Qt::WindowStaysOnTopHint);
    keyboard->move(50,120);
    keyboard->exec();
 //   qDebug("showflag=1");
}else {
   ;//qDebug("showflag=0");
}

}



